/*package com.hmdp.utils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtils {
    public static void main(String[] args) throws MessagingException {
        // 测试发送邮件，替换为接收邮箱
        sendTestMail("3381902370@qq.com", achieveCode());
    }

    public static void sendTestMail(String email, String code) throws MessagingException {
        // 创建Properties类用于记录邮箱的属性
        Properties props = new Properties();
        // 关键修改1：启用SSL加密（QQ邮箱强制要求）
        props.put("mail.smtp.ssl.enable", "true");
        // 表示SMTP发送邮件，必须进行身份验证
        props.put("mail.smtp.auth", "true");
        // QQ邮箱SMTP服务器地址
        props.put("mail.smtp.host", "smtp.qq.com");
        // 关键修改2：SSL端口使用465（587端口需配合STARTTLS，兼容性较差）
        props.put("mail.smtp.port", "465");
        // 发件人邮箱（必须与授权码对应）
        props.put("mail.user", "3381902370@qq.com");
        // 你的SMTP授权码（已填写，注意保密）
        props.put("mail.password", "mmhrrhzvqdvzdaig");
        // 关键修改3：设置SSL工厂类（避免部分环境下的证书问题）
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.port", "465");

        // 构建授权信息，用于SMTP身份验证
        Authenticator authenticator = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                String userName = props.getProperty("mail.user");
                String password = props.getProperty("mail.password");
                return new PasswordAuthentication(userName, password);
            }
        };

        // 使用环境属性和授权信息创建邮件会话
        Session mailSession = Session.getInstance(props, authenticator);
        // 开启调试模式（可选，便于查看发送日志）
        mailSession.setDebug(true);

        // 创建邮件消息
        MimeMessage message = new MimeMessage(mailSession);
        // 设置发件人（需与mail.user一致）
        InternetAddress from = new InternetAddress(props.getProperty("mail.user"));
        message.setFrom(from);

        // 设置收件人
        InternetAddress to = new InternetAddress(email);
        message.setRecipient(MimeMessage.RecipientType.TO, to);

        // 设置邮件标题
        message.setSubject("Kyle's Blog 邮件测试");

        // 设置邮件内容体
        message.setContent("尊敬的用户:你好!\n注册验证码为:" + code + "(有效期为一分钟,请勿告知他人)", "text/html;charset=UTF-8");

        // 发送邮件
        Transport.send(message);
        System.out.println("邮件发送成功！");
    }

    public static String achieveCode() {
        // 验证码生成逻辑（保持不变）
        String[] beforeShuffle = new String[]{"2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F",
                "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
                "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
                "w", "x", "y", "z"};
        List<String> list = Arrays.asList(beforeShuffle);
        Collections.shuffle(list);
        StringBuilder sb = new StringBuilder();
        for (String s : list) {
            sb.append(s);
        }
        return sb.substring(3, 8);
    }
}*/